package com.ds.infrastructure.hyperspace.container.internal;

import io.netty.util.concurrent.FastThreadLocalThread;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author  Weishaoying
 */
public class HyperspaceThreadFactory implements ThreadFactory {

    public static final String PREFIX = "Hyperspace-";
    public static final String THREAD_POSTFIX = "-thread-";

    private final AtomicInteger THREAD_COUNT = new AtomicInteger(0);

    private final String postfix;

    public HyperspaceThreadFactory(String postfix) {
        this.postfix = postfix;
    }

    @Override
    public Thread newThread(Runnable runnable) {
        return new FastThreadLocalThread(runnable, PREFIX + postfix +
                THREAD_POSTFIX + THREAD_COUNT.incrementAndGet());
    }
}
